package kr.ac.kaist.ysproject;

import java.util.ArrayList;

import kr.ac.kaist.ysproject.data.DataSmartMsgInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

public class SmartMessageListAdapter extends ArrayAdapter<DataSmartMsgInfo> {

	private Context mContext;
	private int mResource;
	private ArrayList<DataSmartMsgInfo> mList;
	private LayoutInflater mInflater;

	public SmartMessageListAdapter(Context context, int layoutResource, ArrayList<DataSmartMsgInfo> objects)
	{
		super(context, layoutResource, objects);
		this.mContext = context;
		this.mResource = layoutResource;
		this.mList = objects;
		this.mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}


	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		DataSmartMsgInfo msgInfo = mList.get(position);

		if(convertView == null)
		{
			convertView = mInflater.inflate(mResource, null);
		}

		if(msgInfo != null)
		{
			TextView tvName = (TextView) convertView.findViewById(R.id.tv_name);
			TextView tvTime = (TextView) convertView.findViewById(R.id.tv_time);
			TextView tvDayOfWeek = (TextView) convertView.findViewById(R.id.tv_dayofweek);
			TextView tvRespect = (TextView) convertView.findViewById(R.id.tv_respect);
			TextView tvTalkingWay = (TextView) convertView.findViewById(R.id.tv_talkingway);
			TextView tvCategory = (TextView) convertView.findViewById(R.id.tv_category);
			TextView tvSendType = (TextView) convertView.findViewById(R.id.tv_sendtype);

			tvName.setText(msgInfo.getName());
			tvTime.setText(msgInfo.getTime() + "   +-" + msgInfo.getTimeDev() + "분");
			
			if (msgInfo.getWeeklyRepeat().equals("")) {
				tvDayOfWeek.setText(msgInfo.getDate());
			} else {
				tvDayOfWeek.setText(msgInfo.getWeeklyRepeat());
			}
			
			if (msgInfo.getRespect().equals("")) {
				tvRespect.setText(msgInfo.getManualMsg());
				tvTalkingWay.setVisibility(View.GONE);
				tvCategory.setVisibility(View.GONE);

			} else {
				tvTalkingWay.setVisibility(View.VISIBLE);
				tvCategory.setVisibility(View.VISIBLE);
				tvRespect.setText("존칭 : " + msgInfo.getRespect());
				tvTalkingWay.setText("말투 : " + msgInfo.getTalkingWay());
				tvCategory.setText("상황 : " + msgInfo.getCategory());
			}
			
			tvSendType.setText("[" + msgInfo.getSendType() + "]");
		}

		return convertView;
	}
}
